package com.cskaoyan.kpi.pv;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName DailyPVMapper
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2022/1/19 9:19
 * @Version V1.0
 **/
public class DailyPVMapper extends Mapper<Object, Text, Text, IntWritable> {

    private Text mapperKey = new Text();

    private IntWritable intWritable = new IntWritable(1);

    @Override
    protected void map(Object key, Text value, Context context) throws IOException, InterruptedException {
        // 106.87.2.229---中国:重庆市:未知---2022-01-14 08:01:53---http://115.29.141.32:8085/#/mall/show/goodsList/190/all---firefox
        String line = value.toString();
        if(line == null || "".equals(line.trim())){
            return;
        }
        String[] parts = line.split("---");
        //取出时间中的日期的部分 2022-01-14 08:01:53
        String datetime = parts[2];
        String[] s = datetime.split(" ");
        //2022-01-14
        mapperKey.set(s[0]);
        context.write(mapperKey, intWritable);

    }
}
